package logic

import (
	"context"
	"shop_srv/goods"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ReleaseGoodLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewReleaseGoodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReleaseGoodLogic {
	return &ReleaseGoodLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ReleaseGoodLogic) ReleaseGood(req *types.ReleaseGoodRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	_, err = l.svcCtx.GoodsSrv.CreateGoods(l.ctx, &goods.CreateGoodsRequest{
		GoodsTitle:  req.GoodsTitle,
		GoodsPrice:  req.GoodsPrice,
		GoodsStock:  req.GoodsStock,
		GoodsCover:  req.GoodsCover,
		GoodsStatus: req.GoodsStatus,
	})
	if err != nil {
		return &types.Response{
			Code:    -1,
			Message: "商品添加失败",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    0,
		Message: "发布成功ok",
		Data:    nil,
	}, nil
}
